<template>
  <el-table :data="tableData" size="mini">
    <el-table-column prop="stageId" label="阶段" align="center" />
    <el-table-column prop="setTemperature" label="设定温度" align="center">
      <template slot-scope="scope"> {{ scope.row.setTemperature }}℃ </template>
    </el-table-column>
    <el-table-column prop="startTime" label="开始时间" align="center">
      <template slot-scope="scope">
        {{ scope.row.startTime | formatDate }}
      </template>
    </el-table-column>
    <el-table-column prop="startTemperature" label="开始温度" align="center">
      <template slot-scope="scope">
        {{ scope.row.startTemperature }}℃
      </template>
    </el-table-column>
    <el-table-column prop="endTime" label="结束时间" align="center">
      <template slot-scope="scope">
        {{ scope.row.endTime | formatDate }}
      </template></el-table-column
    >
    <el-table-column prop="endTemperature" label="结束温度" align="center">
      <template slot-scope="scope"> {{ scope.row.endTemperature }}℃ </template>
    </el-table-column>
    <el-table-column prop="col" label="运行时间" align="center">
      <template slot-scope="scope">
        {{ faultDate(scope.row.startTime, scope.row.endTime) }}
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
function timeDifference(new_date, old_date) {
  var new_date = new Date(new_date).getTime() + 1000 * 60; //添加一分钟,解决时间差问题 // 新建一个日期对象，默认现在的时间
  var old_date = new Date(old_date); // 设置过去的一个时间点，"yyyy-MM-dd HH:mm:ss"格式化日期
  var difftime = (new_date - old_date) / 1000; // 计算时间差,并把毫秒转换成秒
  var days = parseInt(difftime / 86400); // 天  24*60*60*1000
  var hours = parseInt(difftime / 3600) - 24 * days; // 小时 60*60 总小时数-过去的小时数=现在的小时数
  var minutes = parseInt((difftime % 3600) / 60); // 分钟 -(day*24) 以60秒为一整份 取余 剩下秒数 秒数/60 就是分钟数
  var seconds = parseInt(difftime % 60); // 以60秒为一整份 取余 剩下秒数
  var time = "";
  if (days) {
    time = `${days}天`;
  }
  if (hours) {
    time += `${hours}小时`;
  }
  if (minutes) {
    time += `${minutes}分钟`;
  }
  // if (seconds) {
  //   time += `${seconds}秒`;
  // }
  // var time = `${days}天${hours}小时${minutes}分钟${seconds}秒`;
  return time;
}
export default {
  props: {
    tableData: {
      type: Array,
      default: () => []
    }
  },
  computed: {
    faultDate() {
      return function(faultDate, completeTime) {
        return timeDifference(completeTime, faultDate);
      };
    }
  }
};
</script>

<style>
/* ::v-deep .el-table {
  margin-top: 10px;
  table {
    width: 100% !important;
  }
  .el-table__body,
  .el-table__header {
    width: 100% !important;
  }

  .el-table__body {
    width: 100% !important;
  }
} */
</style>
